#Boa:Dialog:Dialog1

import wx

def create(parent,app):
    return Dialog1(parent,app)

[wxID_DIALOG1, wxID_DIALOG1BUTTONLOGIN, wxID_DIALOG1BUTTONREFRESH, 
 wxID_DIALOG1LISTBOXPLAYERSINGAME, wxID_DIALOG1STATICBOX1, 
 wxID_DIALOG1STATICTEXT1, wxID_DIALOG1TEXTCTRLPLAYERNAME, 
] = [wx.NewId() for _init_ctrls in range(7)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(333, 164), size=wx.Size(358, 387),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'Player name')
        self.SetClientSize(wx.Size(350, 360))
        self.Center(wx.BOTH)
        self.SetThemeEnabled(True)
        self.SetHelpText(u'sex')
        self.Bind(wx.EVT_CLOSE, self.OnDialog1Close)

        self.listBoxPlayersInGame = wx.ListBox(choices=[],
              id=wxID_DIALOG1LISTBOXPLAYERSINGAME, name=u'listBoxPlayersInGame',
              parent=self, pos=wx.Point(16, 28), size=wx.Size(320, 220),
              style=0)

        self.staticBox1 = wx.StaticBox(id=wxID_DIALOG1STATICBOX1,
              label=u'Players in game', name='staticBox1', parent=self,
              pos=wx.Point(8, 8), size=wx.Size(336, 344), style=0)

        self.staticText1 = wx.StaticText(id=wxID_DIALOG1STATICTEXT1,
              label=u'Player name:', name='staticText1', parent=self,
              pos=wx.Point(19, 288), size=wx.Size(63, 13), style=0)

        self.textCtrlPlayerName = wx.TextCtrl(id=wxID_DIALOG1TEXTCTRLPLAYERNAME,
              name=u'textCtrlPlayerName', parent=self, pos=wx.Point(96, 288),
              size=wx.Size(240, 21), style=0, value=u'')

        self.buttonLogin = wx.Button(id=wxID_DIALOG1BUTTONLOGIN,
              label=u'Join game >>', name=u'buttonLogin', parent=self,
              pos=wx.Point(237, 316), size=wx.Size(100, 25), style=0)
        self.buttonLogin.Bind(wx.EVT_BUTTON, self.OnButtonLoginButton,
              id=wxID_DIALOG1BUTTONLOGIN)

        self.buttonRefresh = wx.Button(id=wxID_DIALOG1BUTTONREFRESH,
              label=u'Refresh', name=u'buttonRefresh', parent=self,
              pos=wx.Point(16, 256), size=wx.Size(75, 23), style=0)
        self.buttonRefresh.Bind(wx.EVT_BUTTON, self.OnButtonRefreshButton,
              id=wxID_DIALOG1BUTTONREFRESH)

    def __init__(self, parent,app):
        self._init_ctrls(parent)
        self.app = app
        self.OnButtonRefreshButton( None )

    def OnButtonLoginButton(self, event):
        self.app.player_name = self.textCtrlPlayerName.GetValue().replace(';','').replace(' ','')
        
        if( self.app.server_proxy.join_game( self.app.game_name , self.app.player_name ) ):
            self.EndModal(1)

    def OnDialog1Close(self, event):
        self.EndModal(0)

    def OnButtonRefreshButton(self, event):
        self.listBoxPlayersInGame.Set( self.app.server_proxy.enum_players( self.app.game_name ) )
